import request from '@/utils/request'

// 获取帖子列表
export function getPostList(params) {
  return request({
    url: '/api/posts',
    method: 'get',
    params
  })
}

// 获取帖子详情
export function getPostDetail(id) {
  return request({
    url: `/api/posts/${id}`,
    method: 'get'
  })
}

// 创建帖子
export function createPost(data) {
  return request({
    url: '/api/posts',
    method: 'post',
    data
  })
}

// 更新帖子
export function updatePost(id, data) {
  return request({
    url: `/api/posts/${id}`,
    method: 'put',
    data
  })
}

// 删除帖子
export function deletePost(id) {
  return request({
    url: `/api/posts/${id}`,
    method: 'delete'
  })
}

// 点赞帖子
export function likePost(id) {
  return request({
    url: `/api/posts/${id}/like`,
    method: 'post'
  })
}

// 取消点赞
export function unlikePost(id) {
  return request({
    url: `/api/posts/${id}/unlike`,
    method: 'post'
  })
}

// 获取评论列表
export function getCommentList(postId) {
  return request({
    url: `/api/comments/post/${postId}`,
    method: 'get'
  })
}

// 创建评论
export function createComment(postId, data) {
  return request({
    url: `/api/comments`,
    method: 'post',
    data: {
      ...data,
      postId
    }
  })
}

// 更新评论
export function updateComment(id, data) {
  return request({
    url: `/api/comments/${id}`,
    method: 'put',
    data
  })
}

// 删除评论
export function deleteComment(id) {
  return request({
    url: `/api/comments/${id}`,
    method: 'delete'
  })
} 